#include "testb.h"
#include <QDebug>
#include <QTimer>

TestB::TestB() : QObject(),
    m_thread(new TestThread),
    m_i(0)
{
    QTimer *t = new QTimer();

    connect(m_thread, SIGNAL(started()),
            this, SLOT(do_start()),
            Qt::DirectConnection);

    connect(m_thread, SIGNAL(finished()),
            this, SLOT(do_finish()));

    connect(t, SIGNAL(timeout()),
            this, SLOT(do_timeout()));
    t->setInterval(1000);
    t->start();
}

void TestB::test()
{
    m_thread->start();
}

void TestB::do_start()
{
    qDebug() << __func__ << __LINE__ << QThread::currentThreadId() << " i=" << m_i;
    sleep(3);
    qDebug() << __func__ << __LINE__ << QThread::currentThreadId() << " i=" << m_i;
}

void TestB::do_finish()
{
    qDebug() << __func__ << __LINE__ << QThread::currentThreadId() << " i=" << m_i;
    sleep(3);
    qDebug() << __func__ << __LINE__ << QThread::currentThreadId() << " i=" << m_i;
}

void TestB::do_timeout()
{
    ++m_i;
}
